// pages/test/message/index.js
var App = getApp();
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		list: [],
		page:2,
		nums:0
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function (options) {
		var that = this;
		that.getmessage();
	},
	getmessage: function () {
		var that = this;
		App.ajax.ajax('userInfo.do?method=testScheduleList',{
			JSESSIONID: wx.getStorageSync('JSESSIONID'),
			page:1,
			limit:6,
			status:"已测试",
		},function (res) {
			console.log(res.data)
			for (var i = 0; i < res.data.items.length;i++){
				res.data.items[i].register_date = (res.data.items[i].register_date).substring(0,10)
			}
			var nums = Math.ceil((res.data.totalCount) / 6);
			console.log(nums);
			 that.setData({
				 list: res.data.items,
				 nums: nums
			 })
		})
		console.log(that.data.list)
	},
	//测试详情
	testdetail:function(e){
		var id = e.currentTarget.dataset.id;
		console.log(id);
		var that = this;
		wx.navigateTo({
			url: '../myTestResult/index?id=' + id,
		})
	},
	gotest:function(){
		wx.switchTab({
			url: '../../my/indexPage/index',
		})
	},
	getpage:function(page){
		var that = this;
		if (that.data.page > that.data.nums){
			wx.showToast({
				title: '已加载全部',
				icon:'none'
			})
		}
		else{
		App.ajax.ajax('userInfo.do?method=testScheduleAnswer',{
			page:page,
			JSESSIONID: wx.getStorageSync('JSESSIONID'),
			limit:6
		},function(res){
			for(var i = 0;i<res.data.items.length;i++){
				res.data.items[i].register_date = (res.data.items[i].register_date).substring(0, 10);
			}
			var list = that.data.list;
			var allData = list.concat(res.data.items);
			that.setData({
				list: allData,
				page:that.data.page+1
			})
		})
		}
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function () {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow: function () {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function () {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function () {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function () {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function () {
		var that = this;
		var page = that.data.page;
		that.getpage(page);
	},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function () {

	}
})